package com.amgl.amupush.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by amglh on 2016/8/10.
 */
public class BaseRVAdapter<D, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
    protected Context context;
    protected LayoutInflater inflater;

    List<D> dataList = new ArrayList<>();

    public BaseRVAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setDataList(List<D> dataList) {
        this.dataList.clear();
        this.dataList.addAll(dataList);
    }

    public void addDataList(List<D> dataList) {
        this.dataList.addAll(dataList);
    }

    public D getItem(int position) {
        int count = getItemCount();
        if (position >= 0 && count > position) {
            return dataList.get(position);
        }
        return null;
    }

    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {

    }

    @Override
    public int getItemCount() {
        if (dataList == null)
            return 0;
        return dataList.size();
    }
}
